# @Time    : 2022/7/16 1:37
# @Author  : mobai
# @Email   : 3111283671@qq.com
# @File    : shangji_page.py
# @Software: PyCharm


import unittest
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from pages.base_pageage import BasePage
from selenium.webdriver.support.select import Select


class ShangJiPage(BasePage):
    """商机初始页面"""
    url = "http://192.168.1.151/crm/index.php?m=business"
    TJSJ = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(1) > div > a")
    TJ = (By.LINK_TEXT, "推进")
    GXSJ1 = (By.CSS_SELECTOR, "#form1 > table > tbody > tr:nth-child(1) > td:nth-child(1) > input")
    GXSJ2 = (By.CSS_SELECTOR, "#form1 > table > tbody > tr:nth-child(2) > td:nth-child(1) > input")
    DJSC = (By.ID, "delete")
    WFZD = (By.LINK_TEXT, "我负责的")
    WCJD = (By.LINK_TEXT, "我创建的")
    XSFZ = (By.LINK_TEXT, "下属负责")
    XSCJ = (By.LINK_TEXT, "下属创建的")
    JRLX = (By.LINK_TEXT, "今日需联系")
    BZLX = (By.LINK_TEXT, "本周需联系")
    BYLX = (By.LINK_TEXT, "本月需联系")
    ZWLX = (By.LINK_TEXT, "7日未联系")
    BYWLX = (By.LINK_TEXT, "15日未联系")
    YWLX = (By.LINK_TEXT, "30日未联系")
    ZJCJ = (By.LINK_TEXT, "最近创建")
    ZJGX = (By.LINK_TEXT, "最近更新")
    DJCK = (By.CSS_SELECTOR, "#form1 > table > tbody > tr:nth-child(1) > td:nth-child(12) > a:nth-child(1)")
    DJTJ = (By.CSS_SELECTOR, "body > div.container > div.page-header > ul > li:nth-child(2) > a")
    qjdjd = (By.CSS_SELECTOR, "#dialog-advance > form > table > tbody > tr:nth-child(2) > td:nth-child(2) > select")
    XCLXSJ = (By.ID, "nextstep_time")
    XCLXNR = (By.ID, "nextstep")
    JDMS = (By.CSS_SELECTOR, "#dialog-advance > form > table > tbody > tr:nth-child(4) > td:nth-child(2) > textarea")
    JSTJ = (By.CSS_SELECTOR, "#dialog-advance > form > table > tbody > tr:nth-child(5) > td:nth-child(2) > input.btn.btn-primary")

    def tjsj(self):
        """添加商机"""
        self.driver.find_element(*self.TJSJ).click()

    def tj(self):
        """点击推进"""
        self.driver.find_element(*self.TJ).click()

    def gxsj1(self):
        """勾选商机1"""
        self.driver.find_element(*self.GXSJ1).click()

    def gxsj2(self):
        """勾选商机2"""
        self.driver.find_element(*self.GXSJ2).click()

    def djsc(self):
        """点击删除"""
        self.driver.find_element(*self.DJSC).click()

    def wfzd(self):
        """点击我负责的"""
        self.driver.find_element(*self.WFZD).click()

    def wcjd(self):
        """点击我创建的"""
        self.driver.find_element(*self.WCJD).click()

    def xsfz(self):
        """下属负责"""
        self.driver.find_element(*self.XSFZ).click()

    def xscj(self):
        """下属创建的"""
        self.driver.find_element(*self.XSCJ).click()

    def jrlx(self):
        """今日需联系"""
        self.driver.find_element(*self.JRLX).click()

    def bzlx(self):
        """本周需联系"""
        self.driver.find_element(*self.BZLX).click()

    def bylx(self):
        """本月需联系"""
        self.driver.find_element(*self.BYLX).click()

    def zwlx(self):
        """7日未联系"""
        self.driver.find_element(*self.ZWLX).click()

    def bywlz(self):
        """15日未联系"""
        self.driver.find_element(*self.BYWLX).click()

    def ywlx(self):
        """30日未联系"""
        self.driver.find_element(*self.YWLX).click()

    def zjcj(self):
        """最近创建"""
        self.driver.find_element(*self.ZJCJ).click()

    def zjgx(self):
        """最近更新"""
        self.driver.find_element(*self.ZJGX).click()

    def djck(self):
        """点击查看"""
        self.driver.find_element(*self.DJCK).click()

    def djtj(self):
        """点击统计"""
        self.driver.find_element(*self.DJTJ).click()

    def tjxx(self,xclxsj,xclxnr,jdms):
        """推进信息"""
        QJDJD = self.driver.find_element(*self.qjdjd)
        select = Select(QJDJD)
        select.select_by_visible_text("深度沟通")  # 选择前进到阶段
        self.driver.find_element(*self.XCLXSJ).send_keys(xclxsj)  # 输入下次联系时间
        self.driver.find_element(*self.XCLXNR).send_keys(xclxnr)  # 输入下次联系内容
        self.driver.find_element(*self.JDMS).send_keys(jdms)  # 输入阶段描述
        sleep(2)
        self.driver.find_element(*self.JSTJ).click()  # 点击推进（结束时）

    def qdsc(self):
        """点击确定删除"""
        self.driver.switch_to.alert.accept()
